# -*- encoding: utf-8 -*-
import json
import sys
sys.path.append('../public') 
import webHttp
from webHttp import *
import os

def getData(scale,datalen):
	url = "https://quotes.sina.cn/cn/api/json_v2.php/CN_MarketDataService.getKLineData?"
	url = url + "symbol=sh000001&scale="+ str(scale) +"&ma=&datalen=" + str(datalen)
	return json.loads(get_url(url))

def 保存文本(filename,contents):
	fh = open(filename,'w')
	fh.write(contents)
	fh.close()

def 获取文本(txtPath,encoding='utf-8'):
	with open(txtPath,'r',encoding=encoding) as f:
		content = f.read()
	return content

def isUp(ma,lastma):
	val = False
	if(ma>lastma):
		val = True
	return val


def UpDownVal(ma5,lastma5,ma10,lastma10,ma30,lastma30):
	val = False
	if(isUp(ma5,lastma5) and isUp(ma10,lastma10) and isUp(ma30,lastma30)):
		if(isUp(ma5,ma10) and isUp(ma10,ma30)):
			val = True
	return val

ma5 = da[1]['ma_price5']
lastma5 = da[0]['ma_price5']
ma10 = da[1]['ma_price10']
lastma10 = da[0]['ma_price10']
ma30 = da[1]['ma_price30']
lastma30 = da[0]['ma_price30']


vol5 = da[1]['ma_volume5']
lastvol5 = da[0]['ma_volume5']
vol10 = da[1]['ma_volume10']
lastvol10 = da[0]['ma_volume10']
vol30 = da[1]['ma_volume30']
lastvol30 = da[0]['ma_volume30']

			
da = getData(15,2)

print(vol5)
print(lastvol5)
print(vol10)
print(lastvol10)
print(vol30)
print(lastvol30)

print(UpDownVal(ma5,lastma5,ma10,lastma10,ma30,lastma30))

print(UpDownVal(vol5,lastvol5,vol10,lastvol10,vol30,lastvol30))

